<% include ../header.ejs %>


<header data-am-widget="header" data-am-sticky class="am-header am-header-default" id="appTemplates-Nav">
    <div class="am-header-left am-header-nav">
        <a href='javascript:history.go(-1)' class="">
            <img class="am-header-icon-custom" src="data:image/svg+xml;charset&#x3D;utf-8,&lt;svg xmlns&#x3D;&quot;http://www.w3.org/2000/svg&quot; viewBox&#x3D;&quot;0 0 12 20&quot;&gt;&lt;path d&#x3D;&quot;M10,0l2,2l-8,8l8,8l-2,2L0,10L10,0z&quot; fill&#x3D;&quot;%23fff&quot;/&gt;&lt;/svg&gt;" alt=""/>
        </a>
    </div>

    <h1 class="am-header-title">
        <a href="#title-link" class="" id="Typeface-whitecolor">编辑组合</a>
    </h1>

    <div class="am-header-right am-header-nav">
        <a id="a_save" onclick="javascript:;" class="" data-am-modal="{target: '#modal-type-add', closeViaDimmer: 0, width: 240, height: 260}">保存</a>
    </div>
</header>

<form name="addstockrecommend" class="am-form" method="post" action="save" data-am-validator>
    <fieldset>
        <div class="am-form-group">
            <label for="doc-vld-name">创建人</label>
            <input type="text" value="王金杰" name = "name" disabled="false">
        </div>
        <div class="am-form-group">
            <label for="doc-vld-name">组合行业：</label>
            <select name="industry" data-am-selected="{btnWidth:'100%'}" placeholder="选择行业" required >
               <option value="1">全行业</option>
                <option value="2">房地产</option>
                <option value="3">环保</option>
                <option value="4">电子</option>
                <option value="5">军工</option>
            </select>
        </div>

        <div class="am-form-group">
            <label for="doc-vld-name">组合简介:</label>
            <textarea class="" rows="5" id="doc-ta-1" name = "content"></textarea>

        </div>

    </fieldset>
</form>

<script type="text/javascript">
    $(function() {
//        //设置默认时间为当天
//        $('#start_datetime').datepicker('setValue', $('#start_datetime').data('init') || new Date().format('yyyy-MM-dd'));
//
//        //自动填入当天价格
//        $('#stockId').on('change', function() {
//            var stockNoName=  $('#stockId').find("option:selected").text();
//            stockNo=stockNoName.split(" ")[0];
//            $.get("/smtool_project/wxapp/api/stock/getRealPrice?stockCode="+stockNo,function(repdata,status){
//                $('#importPrice').val(repdata);
//                $('#importPrice').focus();
//            });
//        });
//
//         //修改person值
//         $('#seller').on('change', function() {
//             var seller=  $('#seller').val();
//             $.get("/smtool_project/wxapp/api/user/getUserListBySeller?seller="+seller,function(repdata,status){
//                    $('#createUserId').children().remove();
//                    $.each(repdata,function(i,obj){
//                        $('#createUserId').append("<option value='"+obj.rowId+"' >"+obj.name+"</option>");
//                    });
//             });
//         });

    });
    $(".company-data-ajax").select2({
        ajax: {
            url: "../../api/dicStock/getStockList",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    name: params.term
                };
            },
            processResults: function (data, params) {
                params.page = params.page || 1;
                var newdata = $.map(data.obj, function (obj) {
                    obj.id = obj.id || obj.rowId; // replace pk with your identifier
                    obj.text = obj.text ||obj.stockCode+" "+ obj.name;
                    return obj;
                });

                return {
                    results: newdata,
                    pagination: {
                        more: (params.page * 30) < data.total_count
                    }
                };
            },
            cache: true
        },
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 2
    });

    //保存功能
    $(function() {
        $('#a_save').on('click', function() {
            var importPrice=  $('#importPrice').val();
            var expectPrice= $('#expectPrice').val();
            var expectRate=  getExpectRate(importPrice,expectPrice)

            $('#expectRate').val(toDecimal(expectRate)+"%")
            $('#save').click()
        });
    });


    function getExpectRate(importPrice,expectPrice)
    {
        return (expectPrice-importPrice)*100/importPrice
    }

    function toDecimal(x) {
        var f = parseFloat(x);
        if (isNaN(f)) {
            return;
        }
        f = Math.round(x*100)/100;
        return f;
    }
</script>
<% include ../footer.ejs %>